#include "proto/internal.pb.h"
#include "OpCompute.h"
#include "Exp.h"

using namespace internal;

OpCompute::OpCompute(const ComputeOperation& operation) {
	source = createOp(operation.source());
	int n = operation.expressions().size();
	for (int i = 0; i < n; i++) {
		expression.push_back(createExp(operation.expressions(i), source->getOutput()));
		output.push_back(expression.back()->getOutputElem());
	}
}

int OpCompute::doit() {
	int ret = source->doit();
	if (ret == -1) return -1;
	else {
		for (size_t i = 0; i < expression.size(); i++)
			expression[i]->doit(ret);
		return ret;
	}
}
